<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录 - 个人数据侵权损害赔偿智能预测系统</title>
    <style>
        body {
            background-image: url('images/background.png');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            height: 100vh;
            margin: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: Arial, sans-serif;
        }
        
        .login-card {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
            width: 400px;
        }
        
        .login-card h1 {
            margin: 0 0 20px;
            text-align: center;
            color: #333;
            font-size: 24px;
        }
        
        .form-group {
            margin-bottom: 15px;
        }
        
        .form-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
            color: #000; /* 添加黑色文字颜色 */
        }
        
        .login-btn {
            width: 100%;
            padding: 12px;
            background: #4e73df;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        
        .login-btn:hover {
            background: #2e59d9;
        }
        
        /* 添加错误提示样式 */
        .error-message {
            display: none;
            color: #dc3545;
            background-color: rgba(220, 53, 69, 0.1);
            border: 1px solid #dc3545;
            border-radius: 4px;
            padding: 10px;
            margin-bottom: 15px;
            text-align: center;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="login-card">
        <h1>个人数据侵权损害赔偿智能预测系统</h1>
        <!-- 添加错误提示区域 -->
        <div id="errorMessage" class="error-message"></div>
        <div class="form-group">
            <input type="text" id="username" placeholder="请输入用户名" required>
        </div>
        <div class="form-group">
            <input type="password" id="password" placeholder="请输入密码" required>
        </div>
        <button class="login-btn" onclick="login()">登录</button>
    </div>

    <script>
        // 检查登录状态
        if(localStorage.getItem('isLoggedIn') === 'true') {
            window.location.href = 'index.html';
        }

        function showError(message) {
            const errorDiv = document.getElementById('errorMessage');
            errorDiv.style.display = 'block';
            errorDiv.textContent = message;
            
            // 3秒后自动隐藏错误信息
            setTimeout(() => {
                errorDiv.style.display = 'none';
            }, 3000);
        }

        function login() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;

            if(!username) {
                showError('请输入用户名');
                return;
            }

            if(!password) {
                showError('请输入密码');
                return;
            }

            fetch('/api/auth/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    username: username,
                    password: password
                })
            })
            .then(response => {
                if (response.status === 200) {
                    localStorage.setItem('isLoggedIn', 'true');
                    localStorage.setItem('username', username);
                    window.location.href = 'index.html';
                } else {
                    showError('用户名或密码错误');
                }
            })
            .catch(error => {
                console.error('Error:', error);
                showError('登录失败，请重试');
            });
        }
    </script>
</body>
</html>